package com.telit.firecommand.config;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * Create by Chencf 2022/11/10
 * xxljob启动配置类
 */
@Slf4j
@Configuration
public class XxlJobConfig {

    @Value("${xxl.job.admin.addresses}")
    private String xxlJobAdminAddress;

    @Value("${xxl.job.accessToken}")
    private String xxlJobAccessToken;

    @Value("${xxl.job.executor.appname}")
    private String xxlJobExecutorAppName;

    @Value("${xxl.job.executor.title}")
    private String xxlJobExecutorTitle;

    @Value("${xxl.job.executor.ip}")
    private String xxlJobExecutorIP;

    @Value("${xxl.job.executor.port}")
    private int xxlJobExecutorPort;

    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(xxlJobAdminAddress);
        xxlJobSpringExecutor.setAppname(xxlJobExecutorAppName);
        // 不配置或忽略此参数，则会自动获取本地网卡
        xxlJobSpringExecutor.setIp(xxlJobExecutorIP);
        // 不配置或忽略此参数，则会随机选择端口
        xxlJobSpringExecutor.setPort(xxlJobExecutorPort);
        xxlJobSpringExecutor.setAccessToken(xxlJobAccessToken);
        return xxlJobSpringExecutor;
    }

}

